from PyQt6.QtWidgets import (
    QApplication, QMainWindow, QHBoxLayout, QVBoxLayout,QGridLayout,
    QGroupBox, QPushButton, QLabel, QLineEdit, QWidget
)

class LayoutWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.setWindowTitle("布局演示")
        self.setGeometry(100, 100, 500, 400)
        
        # 主布局
        main_layout = QHBoxLayout()
        
        # 左侧面板 - 垂直布局
        left_panel = QGroupBox("设置")
        left_layout = QVBoxLayout()
        left_layout.addWidget(QPushButton("设置1"))
        left_layout.addWidget(QPushButton("设置2"))
        left_layout.addStretch()  # 添加弹性空间
        left_panel.setLayout(left_layout)
        
        # 右侧面板 - 网格布局
        right_panel = QGroupBox("内容")
        grid_layout = QGridLayout()
        
        # 添加控件到网格
        grid_layout.addWidget(QLabel("用户名:"), 0, 0)
        grid_layout.addWidget(QLineEdit(), 0, 1)
        grid_layout.addWidget(QLabel("密码:"), 1, 0)
        grid_layout.addWidget(QLineEdit(), 1, 1)
        grid_layout.addWidget(QPushButton("登录"), 2, 0, 1, 2)  # 跨2列
        
        right_panel.setLayout(grid_layout)
        
        # 将左右面板添加到主布局
        main_layout.addWidget(left_panel, 1)  # 第二个参数是拉伸因子
        main_layout.addWidget(right_panel, 2)
        
        # 设置中心部件
        container = QWidget()
        container.setLayout(main_layout)
        self.setCentralWidget(container)

# 使用示例
app = QApplication([])
window = LayoutWindow()
window.show()
app.exec()